package hl.action;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ModelDriven;

import hl.pageModel.Member;
import hl.pageModel.Bar;
import hl.pageModel.DataGrid;
import hl.pageModel.Json;
import hl.service.MemberService;

@Namespace("/")
@Action(value = "memberAction")
public class MemberAction extends BaseAction implements ModelDriven<Member> {

	Member member = new Member();

	private MemberService memberService;

	@Override
	public Member getModel() {
		return member;
	}

	public MemberService getMemberService() {
		return memberService;
	}

	@Autowired
	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}


	public void add() {
		Json j = new Json();
		try {
			memberService.save(member);
			j.setSuccess(true);
			j.setMsg("增加成功");

		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}

	public void getDatagrid() {
		DataGrid d = memberService.getDatagrid(member);
		super.writeJson(d);
	}

	public void edit() {
		Json j = new Json();
		try {
			memberService.edit(member);
			j.setSuccess(true);
			j.setMsg("修改成功！");

		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}

	public void remove() {
		Json j = new Json();
		try {
			memberService.remove(member);
			j.setSuccess(true);
			j.setMsg("删除成功！");

		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}
	
	public void getGenderBar() {
		Bar d = memberService.getGenderBar();
		super.writeJson(d);
	}
	
	public void getComboBox() {
		super.writeJson(memberService.getComboBox(member));
	}
}
